#include<bits/stdc++.h>
using namespace std;
#define N 3000010
vector<int>lk[N];
const int p=998244353;
int n,vis[N],ru[N];
int tr[N][2],f[N],ans;
string s;

bool ck(int x,int y)
{
	return ((x==0&&y==0)||(x==1&&y==1)||(x==1&&y==0));
}

void pb(int x,int y)
{
	//return;
	int sz=lk[x].size();
	for(int i=0;i<sz;++i)
	{
		int z=lk[x][i];
		if(vis[z]!=y){vis[z]=y;lk[y].push_back(z);}
	}
}

void gt()
{
	int la=-1;
	for(int i=1;i<=n;++i)
	{
		int x=s[i-1]-'A',j=i+1;
		tr[i][x]=j;
		if(ck(la,x)){vis[i-1]=j;lk[j].push_back(i-1);pb(i-1,j);}
		int sz=lk[i].size();
		for(int k=0;k<sz;++k)
		{
			int op=lk[i][k];
			if(!tr[op][x])
			{
				tr[op][x]=j;
				if(op!=1&&ck(s[op-2]-'A',x))
				{
					--op;
					if(vis[op]!=j){vis[op]=j;lk[j].push_back(op);pb(op,j);}
				}
			}
			else
			{
				op=tr[op][x];
				if(vis[op]!=j){vis[op]=j;lk[j].push_back(op);pb(op,j);}
			}
		}
		la=x;
		//cout<<j<<':'<<endl;sz=lk[j].size();for(int k=0;k<sz;++k)cout<<lk[j][k]<<' ';cout<<endl;
	}
}

void bfs()
{
	queue<int>q;q.push(1);f[1]=1;
	for(int i=1;i<=n;++i){++ru[tr[i][0]];++ru[tr[i][1]];}
	while(!q.empty())
	{
		int x=q.front();q.pop();
		int y1=tr[x][0],y2=tr[x][1];
		if(y1){f[y1]=(f[y1]+f[x])%p;--ru[y1];if(!ru[y1])q.push(y1);}
		if(y2){f[y2]=(f[y2]+f[x])%p;--ru[y2];if(!ru[y2])q.push(y2);}
	}
	int sz=lk[n+1].size();
	ans=f[n+1];
	for(int i=0;i<sz;++i)ans=(ans+f[lk[n+1][i]])%p;
}

int main()
{
	freopen("song.in","r",stdin);
	freopen("song.out","w",stdout);
	cin>>s;n=s.length();
	int fg=1;
	for(int i=1;i<n;++i)if(s[i]==s[i-1]){fg=0;break;}
	if(fg)
	{
		if(s[n-1]=='B')--n;
		if(n>0&&s[0]=='A')--n;
		printf("%d",n/2+1);
		return 0;
	}
	gt();
	bfs();
	printf("%d",ans);
	return 0;
}
